<template>
	<view class="box">
		<view class="tips" v-if="type==1">
			<view class="tips-title">
				<image class="myImg" src="@/static/images/index/wait.png"></image>
				<view class="title1">待审核</view>
			</view>
			<view>随手拍提交成功,等待审核中</view>
		</view>
		<view class="main-list">
			<view class="item-list" style="border-bottom: 2rpx solid #F5F5F5;">
				<view class="text">
					隐患位置
				</view>
				<view class="right-text ziti">{{dataForm.dangerSite}}</view>
			</view>
			<view class="item-list text">隐患描述</view>
			<view class="item-list ziti" style="padding-top: 0;border-bottom: 2rpx solid #F5F5F5;">{{dataForm.dangerDesc}}</view>

			<view class="item-list text">隐患照片</view>
			<view class="item-list" style="padding-top: 0;padding-bottom: 16rpx;border-bottom: 2rpx solid #F5F5F5;">
				<view class="imgBox" v-if="fileList1.length">
					<view class="img" v-for="v in imgList">
						<image @tap="previewImage(v,imgList)" :src="v"></image>
					</view>
					<video class="video" v-for="v in videoList" :src="v"></video>
				</view>
				<view v-else>无</view>
			</view>
			<view class="item-list" style="border-bottom: 2rpx solid #F5F5F5;" v-if="current == 0"><span
					class="text">隐患审核部门</span><span class="ziti">{{dataForm.auditDeptName}}</span></view>
			<view class="item-list" style="border-bottom: 2rpx solid #F5F5F5;"><span class="text">提交人</span><span class="ziti">{{dataForm.userName}}</span></view>
			<view class="item-list" style="border-bottom: 2rpx solid #F5F5F5;"><span class="text">提交时间</span><span class="ziti">{{dataForm.createTime}}</span></view>
		</view>

		<view class="kiss-btn" v-if="type==2">
			<view class="btn-left" @click="$dianji(togoSubmitCurrent,'onoff2')">审核不通过</view>
			<view class="btn-right" @click="$dianji(sumbit,'onoff')">审核通过</view>
		</view>
		<u-popup :show="show" mode="bottom">
			<view class="popupBox">
				<view class="title">审核不通过</view>
				<u--textarea v-model="popupContent" count maxlength="120" :cursorSpacing='70'
					placeholder="请输入审核不通过原因"></u--textarea>
				<view class="my-bottom-double">
					<view class="btn-left" @click="$dianji(close,'onoff4')">取消</view>
					<view class="btn-right" @click="$dianji(noPass,'onoff3')">提交</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import uploadVideo from '@/components/uploadVideo/index.vue';
	export default {
		components: {
			uploadVideo
		},
		data() {
			return {
				show: false,
				popupContent: '',
				onoff: true,
				onoff2: true,
				onoff3: true,
				onoff4: true,
				fileList1: [],
				file: '',
				sourceType: ['album', 'camera'],
				randomId: '',
				dataForm: {},
				type: '',
				current: 0,
				imgList: [],
				videoList: []
			}
		},
		onLoad(options) {
			this.randomId = options.randomId
			this.type = options.type
			this.current = options.current
			this.initData()
		},
		methods: {
			initData() {
				uni.$u.http.get(`/check/mobile/appSmallTake/smallTakeDetail/${this.randomId}`).then(res => {
					if (res.code == 0) {
						this.dataForm = res.data
						if (res.data.dangerPhoto != '') {
							// 图片回显
							let arr = []
							res.data.dangerPhoto.split(',').map(item => {
								let dd = {
									url: item
								}
								arr.push(dd);
							})
							this.fileList1 = arr
							this.fileList1.forEach(item => {
								let str = item.url.split('?')[0]
								if (str.substring(str.length - 3, str.length) == 'mp4') {
									this.videoList.push(item.url)
								} else {
									this.imgList.push(item.url)
								}
							})
						}
					}
				}).catch(err => {})
			},
			//预览图片
			previewImage: function(e, s) {
				let imgList = []
				if (s.pictures) {
					imgList = this.getpictureList(s.pictures)
				} else {
					imgList = s
				}
				uni.previewImage({
					current: e,
					urls: imgList,
				});
			},
			//处理图片
			getpictureList(pictureinfo) {
				if (pictureinfo) {
					var splitAdd = pictureinfo.split(",");
					var imgList = []
					for (let i = 0; i < splitAdd.length; i++) {
						let iOrV = splitAdd[i].split("?")[0].split(".")
						let iOrVL = splitAdd[i].split("?")[0].split(".").length - 1
						if (iOrV[iOrVL] != 'mp4') {
							imgList.push(splitAdd[i])
						}
					}
					return imgList
				} else {
					return []
				}
			},
			togoSubmitCurrent() {
				this.show = true
			},
			sumbit() {
				// 去审核通过
				uni.navigateTo({
					url: `/pages/subPackagesA/randomClap/checkRandom?randomId=${this.randomId}`
				})
			},

			close() {
				this.show = false
				this.popupContent = ''
			},
			noPass() {
				if (!this.popupContent || this.popupContent == '') {
					uni.$u.toast('请填写不通过原因')
					return
				}
				// 审核不通过提交
				const params = {
					auditStatus: 2,
					id: this.randomId,
					reason: this.popupContent
				}
				uni.$u.http.post(`/check/mobile/appSmallTake/approveSmallTake`, params).then(res => {
					if (res.code == 0) {
						uni.$u.toast('提交成功')
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100vh;
		background: #ffffff;
	}

	.box {
		.tips {
			font-size: 28rpx;
			color: #8C8C8C;
			background: #F5F5F5;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding: 32rpx 0;

			.tips-title {
				display: flex;
				justify-content: center;
				align-items: center;

				.myImg {
					width: 24px;
					height: 24px;
					margin-right: 8rpx;
				}

				.title1 {
					font-size: 16px;
					font-weight: 400;
					color: #0F53AC;
					margin: 16rpx 0 8rpx;
				}

			}
		}

		.main-list {
			// padding:0 32rpx;
			background-color: #fff;
			font-size: 34rpx;

			.item-list {
				padding: 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: flex-start;

				.right-text {
					word-break: break-all;
					word-wrap: break-word;
				}
			}

			// .item-list:nth-last-child(5) {
			// 	border-bottom: none;
			// }
			
			// .item-list:nth-last-child(7) {
			// 	border-bottom: none;
			// }

			.text {
				color: #666666;
				min-width: 180rpx;
			}

			.item-upload {
				border-bottom: none;
			}
		}

		.kiss-btn {
			width: 100%;
			background: #ffffff;
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-top: 38rpx;

			.btn-left {
				width: 45%;
				height: 92rpx;
				border-radius: 12rpx;
				background: #ffffff;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #0F53AC;
				border: 1px solid #0F53AC;
				font-size: 34rpx;
				font-weight: 500;
				letter-spacing: 0px;
				line-height: 0px;
			}

			.btn-right {
				width: 45%;
				height: 92rpx;
				border-radius: 12rpx;
				background: #0F53AC;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				font-size: 34rpx;
				font-weight: 500;
				letter-spacing: 0px;
				line-height: 0px;
			}
		}

		.popupBox {
			padding: 32rpx 32rpx 0 32rpx;

			.title {
				text-align: center;
				margin-bottom: 32rpx;
			}

			.my-bottom-double {
				width: 100%;
				display: flex;
				justify-content: space-around;
				align-items: center;
				padding: 20rpx 0;

				.btn-left {
					width: 45%;
					height: 92rpx;
					border-radius: 12rpx;
					background: #ffffff;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #0F53AC;
					border: 1px solid #0F53AC;
					font-size: 34rpx;
					font-weight: 500;
					letter-spacing: 0px;
					line-height: 0px;
				}

				.btn-right {
					width: 45%;
					height: 92rpx;
					border-radius: 12rpx;
					background: #0F53AC;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #fff;
					font-size: 34rpx;
					font-weight: 500;
					letter-spacing: 0px;
					line-height: 0px;
				}
			}
		}
	}

	.imgBox {
		display: flex;

		.img {
			width: 27vw;
			height: 27vw;
			margin-bottom: 4vw;
			margin-right: 4vw;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.video {
			width: 27vw;
			height: 27vw;
			margin-bottom: 4vw;
			margin-right: 4vw;
		}
	}
	
	.ziti{
		font-size: 16px;
		color: #2b2b2b;
		font-weight: 400;
	}
</style>